app.controller("routeInfo", ["$scope", "$rootScope", "$stateParams", "$state", "$http", function($scope, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'route';
	scrollTo(0, 0);
	BackTop()
	$rootScope.record()
	$rootScope.page.goshow = true
	var mySwiper = new Swiper('.banner', {
		autoplay: 2000,
		pagination: '.swiper-pagination',
		observer: true, //修改swiper自己或子元素时，自动初始化swiper
		observeParents: true, //修改swiper的父元素时，自动初始化swiper
	})
	var id = $stateParams.Id //线路id
		//查询线路关联楼盘
		//查询关联楼盘
	var addurl = window.location.href
	if(addurl.split("?")[1]){
		var openid = addurl.split("?")[1].split("=")[1]
		console.log(openid)
		if(!openid){
			
		}else{
			$http({
				type: "post",
				async: true,
				url: "" + $rootScope.Location + "Login/get_user?id="+openid,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}).success(function(data) {
				localStorage.setItem("user_ID",data["list"]["user_Id"])
				localStorage.setItem("token",data["list"]["token"])
			})
		}
	}else{
		
	}	
	$http({
			method: 'post',
			url: '' + $rootScope.Location + 'House/road_house',
			data: {
				Id: id,
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token")
			},
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
		}).success(function(data) {
//			console.log(data)
			$scope.roadHouse = data["list"]
		})
		//查询线路评论
	$http({
			method: 'post',
			url: '' + $rootScope.Location + 'House/road_comment',
			data: {
				Id: id,
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token")
			},
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
		}).success(function(data) {
//			console.log(data)
			$scope.Comment = data["list"]
			$scope.num = data["num"]
			$scope.toComment = function() {
				$state.go("main.routecommentlist", {
					Id: id
				})
			}
		})
		//查询线路详情
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'House/road_detail',
		data: {
			Id: id,
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token")
		},
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}).success(function(data) {
		$rootScope.page.goshow = false
		$scope.Data = data["list"]
		console.log(data)
		var title = data["list"]["title"]
		var desc = data["list"]["intro"]
		var imgUrl = data["list"]["images"]
		$scope.toList = function(){
			localStorage.setItem("recomId",id)
			window.location.href = "recommend/index.html"
		}
		$scope.canapply = data["list"]["is_apply"]
		if($scope.canapply!=1){
			$(".nowBuy").css("pointer-events", "none").css("background", "#a8a8a8");
		}else{
			$(".nowBuy").css("pointer-events", "auto").css("background", "#fe8a76");
		}
			//微信分享
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Share/share_s',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				url: window.location.href
			}
		}).success(function(result) {
//			console.log(result)
			var appid = result.appId;
			var timestamp = result.timestamp;
			var nonceStr = result.nonceStr;
			var signature = result.signature;
			if(localStorage.getItem("user_ID")){
				var urlAfter = window.location.href+"?fff="+localStorage.getItem("user_ID")+""; 
			}else{
				var urlAfter = window.location.href
			}	
			wx.config({
				debug: false, //开启调试模式,调用的所有api的返回值会在客户端alert出来
				appId: appid, // 必填，公众号的唯一标识
				timestamp: timestamp, // 必填，生成签名的时间戳
				nonceStr: nonceStr, // 必填，生成签名的随机串
				signature: signature, // 必填，签名
				jsApiList: [
					'onMenuShareTimeline', //分享到朋友圈
					'onMenuShareAppMessage', //分享给朋友
					'onMenuShareQQ', //分享给QQ好友
					'showOptionMenu'
				]
			});

			wx.ready(function() {
				wx.showOptionMenu();
				wx.onMenuShareTimeline({
					title: title,
					desc: desc, // 分享标题							
					link: urlAfter, // 分享链接
					imgUrl: imgUrl, // 分享图片
					success: function() {
						$rootScope.shareSuccess(2)
						// 用户确认分享后执行的回调函数
					},
					cancel: function() {
						// 用户取消分享后执行的回调函数
					}
				});

				wx.onMenuShareAppMessage({
					title: title, // 分享标题
					desc: desc, // 分享描述
					link: urlAfter, // 分享链接
					imgUrl: imgUrl, // 分享图片
					type: '', // 分享类型,music、video或link，不填默认为link
					dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
					success: function() {
						$rootScope.shareSuccess(1)
						// 用户确认分享后执行的回调函数
					},
					cancel: function() {
						// 用户取消分享后执行的回调函数
					}
				});

				wx.onMenuShareQQ({
					title: title, // 分享标题
					desc: desc, // 分享描述
					link: urlAfter, // 分享链接
					imgUrl: imgUrl, // 分享图标
					success: function(res) {
						$rootScope.shareSuccess(3)
						// 用户确认分享后执行的回调函数
					},
					cancel: function(res) {
						// 用户取消分享后执行的回调函数
					}
				});
			});
			wx.error(function(res) {
//				console.log(res)
			});
		})
		setTimeout(function() {
			var icon = document.querySelectorAll(".comment_first ul")
			for(var i = 0; i < icon.length; i++) {
				var a = icon[i].getAttribute("data-info")
				for(var j = 0; j < a; j++) {
					icon[i].querySelectorAll(".xing")[j].className = "on xing"
				}
			}
		}, 20)
		var starNum = data["list"].group_star
		$scope.collection = data["list"]["member_favorite"]
		$scope.tocollection = function() {
			$http({
				method: 'post',
				url: '' + $rootScope.Location + 'Member/click_collect',
				data: {
					id: id,
					user_Id: localStorage.getItem("user_ID"),
					token: localStorage.getItem("token"),
					type: 1
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
			}).success(function(data) {
				if(data["status"] == 0) {
					$(".addressdialog").show();
					$(".addressdialog").html("请先登录才能收藏");
					$(".addressdialog").fadeOut(1200);
				} else {
					$scope.collection = !$scope.collection
					$(".addressdialog").show();
					$(".addressdialog").html(data["message"]);
					$(".addressdialog").fadeOut(1200);
				}

			})

		}

		$scope.tocomment = function(id) {
			if(!localStorage.getItem("user_ID") && !localStorage.getItem("token")) {
				$(".addressdialog").show();
				$(".addressdialog").html("请先登录才能去评论");
				$(".addressdialog").fadeOut(1200);
			} else {
				$state.go("main.routcomment", {
					Id: '',
					id: id,
					types: 1,
					type: 2
				})
			}
		}

		$scope.goprojectInfo = function(Id, type) {
			if(type == 1) {
				$state.go("main.projectInfo", {
					Id: Id
				})
			} else {
				$state.go("main.newprojectInfo", {
					Id: Id
				})
			}
		}
		setTimeout(function() {
				$rootScope.star(starNum * 2)
			}, 100)
			//		        var con_wid=document.getElementById("star_con").offsetWidth;
			//              var del_star=document.getElementById("del_star");
			//              console.log(con_wid);              
			//              //透明星星移动的像素
			//              var del_move=(n*con_wid)/10;
			//              
			//              del_star.style.backgroundPosition=-del_move+"px 0px";
			//              del_star.style.left=del_move+"px";
		$scope.activeIndex = 0;
		$scope.showprice = data["list"]["combo"][0]["price"]
		$scope.showcontent = data["list"]["combo"][0]["content"]
		$scope.combo_Id = data["list"]["combo"][0]["Id"]
		$scope.chooseIndex = function($index, price, content, Id) {
			$scope.activeIndex = $index
			$scope.showprice = price
			$scope.showcontent = content
			$scope.combo_Id = Id //套餐Id
		}
		$scope.toShopcar = function() {
			if(!localStorage.getItem("user_ID")) {
				$rootScope.register()
			} else {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Order/add_cart',
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						road_Id: id, //线路ID
						combo_Id: $scope.combo_Id, //套餐ID
						num: 1
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
				}).success(function(data) {
					if(data["status"] == 1) {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
						$(".shadow_info").hide();
						$(".groupWarp").slideUp()
						$http({
							method: 'post',
							url: '' + $rootScope.Location + 'Order/cart_list',
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							data: {
								user_Id: localStorage.getItem("user_ID"),
								token: localStorage.getItem("token")
							}
						}).success(function(data) {
							$rootScope.shopcarNum = data["num"]
							if(data["num"] >= 1) {
								$rootScope.page.shopcarNum = true
							} else {
								$rootScope.page.shopcarNum = false
							}
						})
					}
					if(data["status"] == 2) {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
						$state.go("main.login")
					}
					if(data["status"]==4){
						$(".wrapLoginDialog2").show();
						$(".cancle").click(function() {
							$(".wrapLoginDialog2").hide();
						})
						$(".sure").click(function() {
							$(".wrapLoginDialog2").hide();
							$state.go("main.login");
						})
						$rootScope.message = data["message"]
					}
				})
			}

		}
	})
	jQuery(".canHangUp .Ctitle").on("click", function() {
		if(!$(this).hasClass("active")) {
			$(this).addClass("active")
			$(this).parent(".canHangUp").find(".Ctext").slideDown()
				//			$(this).parent(".canHangUp").find(".more_comment").slideDown()
			$(this).find("img").css("width", "0.32rem")
			$(this).find("img")[0].src = "img/arrow1.jpg";
		} else {
			$(this).removeClass("active")
			$(this).parent(".canHangUp").find(".Ctext").slideUp()
				//			$(this).parent(".canHangUp").find(".more_comment").slideUp()
			$(this).find("img").css("width", "0.17rem")
			$(this).find("img")[0].src = "img/arrow.jpg";
		}
	});
	$(".cTitle2").click(function() {
		var flag = $(this).find("i").hasClass('active');
		if(!flag) {
			$(this).find("i").addClass('active');
			$(this).find("i").addClass("icon-combinedshapefuben").removeClass("icon-jiantouxia");
			$(this).parent(".canHangUp").find(".cText").slideUp();
		} else {
			$(this).find("i").removeClass('active');
			$(this).find("i").addClass("icon-jiantouxia").removeClass("icon-combinedshapefuben");
			$(this).parent(".canHangUp").find(".cText").slideDown()
		}
	})
	$(".joinGroup").on("click", function() {
		$(".shadow_info").show();
		$(".groupWarp").slideDown()
	});
	$(".img_cha").on("click", function() {
		$(".shadow_info").hide();
		$(".groupWarp").slideUp()
	});
	$scope.tobuy = function() {
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Order/cart_list',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token")
			}
		}).success(function(data) {
			if(data["status"]!=4){
				var str = {
					road_id: id,
					combo_Id: $scope.combo_Id
				}
				if(!localStorage.getItem("user_ID")) {
					$rootScope.register()
				} else {
					$state.go("main.payment", {
						str: angular.toJson(str),
						num: 2
					})
				}
			}
			if(data["status"]==4){
				$(".wrapLoginDialog2").show();
				$(".cancle").click(function() {
					$(".wrapLoginDialog2").hide();
				})
				$(".sure").click(function() {
					$(".wrapLoginDialog2").hide();
					$state.go("main.login");
				})
				$rootScope.message = data["message"]
			}
		})
		
	}
}])

app.controller("routecommentlist", ["$scope", "$rootScope", "$stateParams", "$state", "$http", function($scope, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'route';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Comment/r_comment_list',
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			road_Id: $stateParams.Id, //线路ID
		},
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
	}).success(function(data) {
		console.log(data)
		$scope.list = data["list"]
		setTimeout(function() {
			var icon = document.querySelectorAll(".comment_first ul")
			for(var i = 0; i < icon.length; i++) {
				var a = icon[i].getAttribute("data-info")
				for(var j = 0; j < a; j++) {
					icon[i].querySelectorAll(".xing")[j].className = "on xing"
				}
			} 
		}, 20)
	})
}])